#!/usr/bin/env bash

MOUNTED=$(shopt -s nullglob dotglob; echo /mnt/share/*)
USER=`whoami`

if (( ${#MOUNTED} )); then
        echo "Remote directory already mounted"
else
    while !(( ${#MOUNTED} )); do
        sudo mount.cifs //corp.wan /mnt/corp -o credentials=/home/$USER/etc/cifs.credo,uid=$USER,forceuid,gid=$USER,forcegid,file_mode=0644,dir_mode=0755,rw,intr,soft,sec=ntlm 2>&1 | grep -q "could not resolve address"
        if [ $? = 0 ]; then
            echo "Corporate network not available"
            break;
        fi
        MOUNTED=$(shopt -s nullglob dotglob; echo /mnt/share/*)
    done
fi
